package net.mihome.app.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.easemob.chatuidemo.activity.LinliquanFragment;

import net.mihome.app.ui.DazibaoFragment;
import net.mihome.app.ui.MineFragment;
import net.mihome.app.ui.RssTypeFragment;

/**
 * Created by ZHAO on 2014/12/29 0029.
 */
public class MyFragmentAdapter extends FragmentPagerAdapter {
    DazibaoFragment dazibaoFragment;
    LinliquanFragment linliquanFragment;
    RssTypeFragment rssTypeFragment;
    MineFragment mineFragment;
    public MyFragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        try{
            switch (i) {
                case 0:
                    if(dazibaoFragment==null) {
                        dazibaoFragment= DazibaoFragment.newInstance();
                    }
                    return dazibaoFragment;
                case 1:
                    if(linliquanFragment==null){
                        linliquanFragment= LinliquanFragment.newInstance();
                    }
                    return linliquanFragment;
                case 2:
                    if(rssTypeFragment==null) {
                        rssTypeFragment = RssTypeFragment.newInstance();
                    }
                    return rssTypeFragment;
                case 3:
                    if(mineFragment==null) {
                        mineFragment = new MineFragment();
                    }
                    return mineFragment;
                default:{
                    if(dazibaoFragment==null){
                        dazibaoFragment=DazibaoFragment.newInstance();
                    }
                    return dazibaoFragment;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return dazibaoFragment;
        }
    }


    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        return;
//        super.destroyItem(container, position, object);
    }
}
